function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}

//培训类型添加
$(function() {
	$("#AddTrainType_div").easydrag();
	$("#AddTrainType_div").setHandler("#AddTrainType_div #AddTrainType_head");
});

//培训类型修改
$(function() {
	$("#UpdateTrainType_div").easydrag();
	$("#UpdateTrainType_div").setHandler("#UpdateTrainType_div #UpdateTrainType_head");
});

function popadd()
{
	if(!RolePowerManager())
	{
		return;
	}
	popupDiv('AddTrainType_div');
}
//添加培训类型
function addTrainType() {
	if(!RolePowerManager())
	{
		return;
	}
	var typename = $("#typename").val();
	if (!typename) {
		alert("请输入名称");
		return;
	} else {
		TrainTypeManager.ifExistName(typename, TrainTypeExists);
	}
}

//

//判断培训类型名称是否存在
function TrainTypeExists(data) {
	if (data) {
		alert("该名称已存在，请更换！");
	} else {
		TrainTypeManager.addByName($("#typename").val(), function(data) {
			if (data) {
				alert("添加成功");
				location.reload();
			} else {
				alert("添加失败，请重试");
			}
		});
	}
}



function updatetype(id)
{
	popupDiv('UpdateTrainType_div');
	TrainTypeManager.getById(id,function(data)
			{
				$("#TypeId").val(data.id);
				$("#TrainTypeId").html(data.id);
				$("#traintypename").val(data.typename);
			});
}
//更新培训类型
function updateTrainType() {
	if(!RolePowerManager())
	{
		return;
	}
	TrainTypeManager.updateByIdAndName($("#TypeId").val(), $("#traintypename").val(), function(data) {
		if (data) {
			alert("修改成功");
			location.reload();
		} else {
			alert("修改失败");
		}
	});
}
//删除培训类型
function deleteTrainType(id) {
	if(!RolePowerManager())
	{
		return;
	}
	if(!confirm("是否确定删除 ？"))
	{
		return;
	}
	TrainTypeManager.deleteById(id, function(data) {
		if (data) {
			alert("删除成功");
			location.reload();
		} else {
			alert("删除失败");
			location.reload();
		}
	});
}

function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="GetTrainType?pageSize="+pageSize;
}